import java.util.Random;

public class CalculationSystemV02 {
    public static void main(String[] args) {
        System.out.println("加减法口算练习系统-v0.2");
        Random random = new Random();
        int totalQuestions = 50;
        int perLine = 4; // 每行显示4道题

        for (int i = 0; i < totalQuestions; i++) {
            int num1, num2, result;
            char operator;

            if (random.nextBoolean()) {
                // 加法：确保和≤100
                num1 = random.nextInt(101); // 0-100
                num2 = random.nextInt(101 - num1); // 0到(100 - num1)
                operator = '+';
                result = num1 + num2;
            } else {
                // 减法：确保差≥0
                num1 = random.nextInt(100); // 0-99
                num2 = random.nextInt(num1 + 1); // 0到num1
                operator = '-';
                result = num1 - num2;
            }

            // 格式化输出（保持对齐）
            System.out.printf("%d %c %d = %d\t", num1, operator, num2, result);
            // 每行结束换行
            if ((i + 1) % perLine == 0) {
                System.out.println();
            }
        }
    }
}